{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0bf9e93a",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "## 优化ASR（自动语音识别机器人）\n",
    "## 连接图灵机器人\n",
    "## 语音合成"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e7a0d3bd",
   "metadata": {},
   "source": [
    "# 优化ASR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "97a614ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "# import ASR\n",
    "from bdasr import fetch_token,asr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "837fcf1c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# xiaoyang:asr\n",
    "\n",
    "API_KEY = 'LDBKKsuoQ8iGWT9T8FHpdgeS'\n",
    "SECRET_KEY = 'T6P5P1WGupsQSclyaqlepf60h9AUliNk'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e52746c1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.679b9a0d8e5373ba4edd641c54c03e1a.2592000.1655828492.282335-26192329'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xy_token = fetch_token(API_KEY,SECRET_KEY)\n",
    "xy_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "a43695d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 准备音频文件\n",
    "import speech_recognition\n",
    "r = speech_recognition.Recognizer()\n",
    "with speech_recognition.Microphone() as source:\n",
    "    audio = r.listen(source)\n",
    "# 将数据保存到wav文件中\n",
    "with open(\"1.wav\", \"wb\") as f: \n",
    "    f.write(audio.get_wav_data(convert_rate=16000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "bc77472d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"corpus_no\":\"7100597568856318525\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"怎么不算呢？\"],\"sn\":\"837056162961653236701\"}\\n'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "asr(token = xy_token, AUDIO_FILE = '1.wav')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "010b1afc",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a9ccacd4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b94e263a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f64f302b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac92656e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8050c704",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "112756e3",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4daa3b2b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f271909a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c55f112",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e6b341a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "973c7553",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ecb0c61",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ce9f0ca",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
